from enum import Enum

from app.model.content.wtrees_column import ColumnModel
from app.serve.wtrees.base import BaseModel
from sqlalchemy import Column, Integer, String, DateTime


class ArticleModel(BaseModel):
    __tablename__ = "wtrees_article"

    class NatureEnum(Enum):
        image_text = 1
        hotspot = 2
        carousel = 3
        recommend = 4

    nature_name = {
        NatureEnum.image_text.value: "图文",
        NatureEnum.hotspot.value: "热点",
        NatureEnum.carousel.value: "轮播",
        NatureEnum.recommend.value: "推荐",
    }

    id = Column(Integer(), primary_key=True)
    title = Column(String(60), nullable=False, comment="标题")
    abstract = Column(String(60), nullable=False, comment="摘要")
    source = Column(String(60), nullable=False, comment="来源")
    nature = Column(Integer(), nullable=False, comment="属性")
    show_time = Column(DateTime(timezone=True), comment='显示时间')
    column_id = Column(String(60), nullable=False, comment="栏目ID")
    content = Column(String(255), comment="正文")

    def get_info(self):
        return {
            "id": self.id,
            "title": self.title,
            "source": self.source,
            "nature": self.nature_name[self.nature],
            "abstract": self.abstract,
            "show_time": self.show_time,
            "column": ColumnModel.get(id=self.column_id),
            "content": self.content

        }
